﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_1189_MaxNumberOfBalloons
{
    class MainProject
    {
        static void Main(string[] args)
        {

            int s = MaxNumberOfBalloons("ballon");
            Console.WriteLine(s);

            Console.ReadKey();
        }
        public static int MaxNumberOfBalloons(string text)
        {
            string balloon = "balon";
            List<Model> models = new List<Model>();
            for (int i = 0; i < balloon.Length; i++) models.Add(new Model(balloon[i], 0)); ;

            for (int i = 0; i < text.Length; i++)
            {
                Model model = models.Where(j => j.c == text[i]).FirstOrDefault();
                if (model!=null) model.num++;
            }
            int min = 0;
            while (true)
            {
                bool isBreak = false;
                foreach (var item in models)
                {
                    Model model = models.Where(j => j.c == item.c).FirstOrDefault();
                    if (model.c=='l'|| model.c=='o')
                    {
                        model.num -= 2;
                    }
                    else
                    {
                        model.num -= 1;
                    }
                    if (model.num<0)
                    {
                        isBreak = true;
                        break;
                    }
                }
                if (isBreak)
                {
                    return min;
                }
                else
                {
                    min++;
                }
            }

        }
        public class Model
        {
            public char c;
            public int num;
            public Model(char c, int num)
            {
                this.c = c;
                this.num = num;
            }
        }
    }
}
